namespace AbleCommerce.Admin.Shipping.Providers.FedEx
{
    using System;
    using AblePlugins.FedEx;
    using CommerceBuilder.Shipping;
    using CommerceBuilder.Utility;

    partial class Register : CommerceBuilder.UI.AbleCommerceAdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            FedExProvider provider = new FedExProvider();
            FedExLogo.ImageUrl = provider.GetLogoUrl(this.Page.ClientScript);
        }

        protected void CancelButton_Click(object sender, EventArgs e)
        {
            Response.Redirect("../Default.aspx");
        }

        protected void NextButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                FedExProvider provider = new FedExProvider();
                provider.Key = Key.Text;
                provider.Password = Password.Text;
                provider.MeterNumber = MeterNumber.Text;
                provider.AccountNumber = AccountNumber.Text;
                provider.AccountActive = true;
                provider.UseTestMode = true;
                ShipGateway gateway = new ShipGateway();
                gateway.ClassId = Misc.GetClassId(provider.GetType());
                gateway.UpdateConfigData(provider.GetConfigData());
                gateway.Name = "FedEx";
                gateway.Enabled = true;
                gateway.Save();
                Response.Redirect(("Configure.aspx?ShipGatewayId=" + gateway.Id.ToString()));
            }
        }
    }
}